<template>
  <view class="container">
    <!-- 添加返回按钮和标题 -->
    <view class="header">
      <view class="header-content">
        <page-header :title="`轮候公示-${region}街道`" subtitle="" start-color="#39c5bb" end-color="#398dee" height="40rpx" />
      </view>
    </view>

    <!-- 标签页切换 -->
    <view class="tabs">
      <view class="tab" :class="{ active: activeTab === 'waiting' }" @click="switchTab('waiting')">
        <text>排队中</text>
      </view>
      <view class="tab" :class="{ active: activeTab === 'completed' }" @click="switchTab('completed')">
        <text>已排到</text>
      </view>
    </view>

    <!-- 进度条 -->
    <view class="progress-wrapper">
		<wd-progress :percentage="progressPercentage" />
    </view>

    <!-- 申请列表 -->
    <view class="application-list">
      <!-- 表头 -->
      <view class="table-header">
        <view class="header-item queue-number">序号</view>
        <view class="header-item license-number">证件号</view>
        <view class="header-item applicant-name">申请人</view>
        <view class="header-item">申请时间</view>
      </view>

      <view class="application-item" v-for="(item, index) in currentList" :key="index">
        <view class="application-header">
          <view class="queue-number">{{ item.queueNumber }}</view>
          <view class="license-number">{{ desensitizeMiddle(item.license) }}</view>
          <view class="applicant-name">{{ desensitize(item.applicant) }}</view>
          <view class="apply-time">{{ item.applyTime }}</view>
        </view>
      </view>

      <view class="empty-notice" v-if="currentList.length === 0">
        <text>暂无数据</text>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import PageHeader from '@/components/page-header/page-header.vue'
import { desensitize, desensitizeMiddle } from '@/utils/util'

// 获取路由参数
const region = ref('')
onMounted(() => {
  const query = uni.getLaunchOptionsSync().query
  region.value = decodeURIComponent(query.region || '')
})

// 标签页状态
const activeTab = ref('waiting')

// 模拟数据 - 排队中
const waitingList = ref([
  {
    queueNumber: '2',
    license: '9236323213232321PE3J',
    applicant: '彭加祥',
    applyTime: '2025-03-03 15:34:41',
    status: '排队中',
    statusClass: 'status-waiting'
  },
  {
    queueNumber: '3',
    license: '92366565464565PJ47',
    applicant: '熊大富',
    applyTime: '2025-03-13 19:22:05',
    status: '排队中',
    statusClass: 'status-waiting'
  }
])

// 模拟数据 - 已排到
const completedList = ref([
  {
    queueNumber: '1',
    license: '9236543243243432KL28',
    applicant: '李下散',
    applyTime: '2025-02-15 09:12:33',
    status: '已排到',
    statusClass: 'status-completed'
  }
])

// 当前显示的列表
const currentList = computed(() => {
  // 对列表数据进行脱敏处理
  const list = activeTab.value === 'waiting' ? waitingList.value : completedList.value
  return list
})

// 进度条
const progressPercentage = computed(() => {
  return activeTab.value === 'waiting' ? 0 : 100
})

const progressText = computed(() => {
  return activeTab.value === 'waiting' ? '0%' : '100%'
})

// 切换标签页
const switchTab = (tab) => {
  activeTab.value = tab
}

// 返回上一页
const goBack = () => {
  uni.navigateBack()
}
</script>

<style lang="scss">
@import '@/styles/common.scss';

.container {
  padding: 20rpx;
}

.header {
  display: flex;
  align-items: center;
  margin-bottom: 20rpx;
}

.back-btn {
  width: 60rpx;
  height: 60rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  margin-right: 10rpx;
  box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.1);
}

.header-content {
  flex: 1;
}

.tabs {
  display: flex;
  background-color: #fff;
  border-radius: 10rpx;
  margin-bottom: 20rpx;
  overflow: hidden;
  position: relative;
  border-bottom: 1px solid #eee;
}

.tab {
  flex: 1;
  padding: 20rpx 0;
  text-align: center;
  position: relative;
}

.tab.active {
  color: #333;
  font-weight: bold;
}

.tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 25%;
  width: 50%;
  height: 4rpx;
  background-color: #f00;
  border-radius: 2rpx;
}

.progress-wrapper {
  position: relative;
  padding: 0 20rpx;
  margin-bottom: 30rpx;
}

.application-list {
  background-color: #fff;
  border-radius: 12rpx;
  padding: 10rpx 20rpx;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
}

/* 表头样式 */
.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20rpx 10rpx;
  background: linear-gradient(90deg, #398dee, #39c5bb);
  color: #fff;
  font-size: 28rpx;
  font-weight: bold;
  border-radius: 8rpx 8rpx 0 0;
  margin-bottom: 10rpx;
}

.header-item {
  text-align: center;
}

.application-item {
  margin-bottom: 15rpx;
  border-bottom: 1rpx solid #ebeef5;
  padding-bottom: 15rpx;
  transition: all 0.3s ease;
}

.application-item:hover {
  background-color: #f8f9fa;
}

.application-item:last-child {
  margin-bottom: 0;
  border-bottom: none;
  padding-bottom: 0;
}

.application-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 28rpx;
  color: #333;
  padding: 10rpx 10rpx;
}

.queue-number {
  width: 10%;
  font-weight: bold;
  text-align: center;
}

.license-number {
  width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.applicant-name {
  width: 20%;
  text-align: center;
}

.apply-time {
  width: 30%;
  text-align: center;
  font-size: 26rpx;
  color: #666;
}

.empty-notice {
  padding: 40rpx 0;
  text-align: center;
  color: #909399;
}
</style>
